<script  setup >
import homePanel from './homePanel.vue'
import homeGoods from './homeGoods.vue'
import { getHomeProductAPI } from '@/api'
import { ref } from 'vue'
import useLazyData from '@/conpositions'
const productGoods = ref([])
const getHomeProductFn = async() => {
  const res = await getHomeProductAPI()
  //   console.log(res)
  productGoods.value = res.result
}
// getHomeProductFn()

const target = useLazyData(getHomeProductFn)
</script>
<template>
  <div class="home-product" ref="target">
    <homePanel :title="item.name" v-for="item in productGoods" :key="item.id" >
      <template v-slot:right>
        <div class="sub" >
          <RouterLink :to="`/category/sub/${obj.id}`" v-for="obj in item.children" :key="obj.id">{{ obj.name }}</RouterLink>

        </div>
        <more />
      </template>
      <div class="box" >
        <RouterLink class="cover" :to="`/goods/${item.id}`">
          <img
            v-imgLazy="item.picture"
            alt=""
          />
          <strong class="label">
            <span>{{ item.name }}</span>
            <span>{{ item.saleInfo }}</span>
          </strong>
        </RouterLink>
        <homeGoods  :goods="item.goods"/>
      </div>
    </homePanel>
  </div>
</template>

<style scoped lang="less">
.home-product {
  background: #fff;
  height: 2900px;
  .sub {
    margin-bottom: 2px;
    a {
      padding: 2px 12px;
      font-size: 16px;
      border-radius: 4px;
      &:hover {
        background: @xtxColor;
        color: #fff;
      }
      &:last-child {
        margin-right: 80px;
      }
    }
  }
  .box {
    display: flex;
    .cover {
      width: 240px;
      height: 610px;
      margin-right: 10px;
      position: relative;
      img {
        width: 100%;
        height: 100%;
      }
      .label {
        width: 188px;
        height: 66px;
        display: flex;
        font-size: 18px;
        color: #fff;
        line-height: 66px;
        font-weight: normal;
        position: absolute;
        left: 0;
        top: 50%;
        transform: translate3d(0, -50%, 0);
        span {
          text-align: center;
          &:first-child {
            width: 76px;
            background: rgba(0, 0, 0, 0.9);
          }
          &:last-child {
            flex: 1;
            background: rgba(0, 0, 0, 0.7);
          }
        }
      }
    }
  }
}
</style>
